package com.onemile.controls;

import java.util.ArrayList;

import com.onemile.app.R;
import com.onemile.entity.model.ECoupon;
import com.onemile.utils.UtiDateTime;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class AdpLV_CouponList extends BaseAdapter
{

   private ArrayList<ECoupon> mList;
   private LayoutInflater mInflater;
   private Context mContext;

   public AdpLV_CouponList(Context context)
   {
	  mList = new ArrayList<ECoupon>();
	  mContext = context;
	  mInflater = LayoutInflater.from(context);
   }

   public void addItem(ArrayList<ECoupon> _list)
   {
	  if (mList != null)
	  {
		 for (ECoupon ecoupon : _list)
		 {
			mList.add(ecoupon);
		 }
	  }
   }

   @Override
   public int getCount()
   {
	  if (mList == null)
	  {
		 return 0;
	  }
	  return mList.size();
   }

   @Override
   public Object getItem(int position)
   {
	  return mList.get(position);
   }

   @Override
   public long getItemId(int position)
   {
	  return 0;
   }

   @Override
   public View getView(int position, View convertView, ViewGroup parent)
   {
	  convertView = mInflater.inflate(R.layout.coupon_item, null);
	  TextView txtCouponName = (TextView) convertView.findViewById(R.id.txtName_coupon_item);
	  TextView txtDate = (TextView) convertView.findViewById(R.id.txtDate_coupon_item);
	  TextView txtState = (TextView) convertView.findViewById(R.id.txtState_coupon_item);
       
	  txtCouponName.setText(mList.get(position).getCouponName());
	  txtDate.setText(String.format("%s-%s",UtiDateTime.DateToStr(mList.get(position).getStartDate()),UtiDateTime.DateToStr(mList.get(position).getEndDate())));
	  switch (mList.get(position).IsUsed())
	  {
		 case 0:
			txtState.setText("未使用");
			break;
		 case 1:
			txtState.setText("已使用");
			break;
	  }
	  return convertView;
   }

}
